home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-10-26 | 16.9 KB | 564 lines |
- (*----------------------------------------------------------------------*
- * *
- * MAGICTOOLS Modula's All purpose GEM Interface Cadre Toolbox *
- * ÿ ÿ ÿ ÿ ÿ *
- *----------------------------------------------------------------------*
- * Version 3.30 02.02.1992 (C)90/91/92 by Peter Hellinger Software *
- *----------------------------------------------------------------------*
- * Dieses Modul ist urheberrechtlich geschtzt. *
- * *
- * Die Verffentlichung des Quelltextes oder Teilen daraus, sowie die *
- * Verbreitung des bersetzten, nicht gelinkten Codes in schriftlicher, *
- * oder maschinenlesbarer Form, insbesondere in Zeitschriften, Mail- *
- * boxen oder anderen Medien bedarf der ausdrcklichen schriftlichen *
- * Einverstndnisserklrung des Autors. *
- * *
- * Die Verbreitung des Moduls als Teil eines gelinkten Programms ist *
- * fr Lizenznehmer ausdrcklich erlaubt! Der Autor behlt sich das *
- * Recht vor, diese Erlaubnis jederzeit und ohne Angaben von Grnden zu *
- * widerrufen. *
- *----------------------------------------------------------------------*)
-
- IMPLEMENTATION MODULE mtWindows;
-
- (*----------------------------------------------------------------------*
- * Int. Vers | Datum | Name | nderung *
- *-----------+----------+------+----------------------------------------*
- * 3.00 | 18.01.92 | Hp | *
- *-----------+----------+------+----------------------------------------*)
-
-
-
- (* IMPLEMENTATION FR >>> Megamax-Modula-2 <<< *)
- (* *)
- (*$R- Range-Checks *)
- (*$S- Stack-Check *)
- (* *)
- (*----------------------------------------------*)
-
-
-
-
-
-
- FROM MagicSys IMPORT Nil, Null, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6,
- Bit7, Bit8, Bit9, Bit10, Bit11, Bit12, Bit13, Bit14,
- Bit15, LOC, Byte, ByteSet, sWORD, sINTEGER, sCARDINAL,
- sBITSET, lINTEGER, lCARDINAL, lWORD, lBITSET,
- CastToChar, CastToByte, CastToByteset, CastToInt,
- CastToCard, CastToBitset, CastToWord, CastToLInt,
- CastToLCard, CastToLBitset, CastToLWord, CastToAddr,
- TosVersion, Accessory, Basepage, SysHeader, TosDate;
-
-
-
-
-
-
-
-
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
-
-
-
-
- FROM SYSTEM IMPORT ADDRESS, ADR, TSIZE;
- FROM MagicAES IMPORT AESIntIn, AESCall, AESIntOut, VSLIDE, HSLIDE,
- NAME, INFO, WindGet, WindSet, WFNAME, WFINFO,
- WFWORKXYWH, WFCURRXYWH, WFPREVXYWH, WFFULLXYWH,
- WFHSLIDE, WFVSLIDE, WFTOP, WFFIRSTXYWH, WFNEXTXYWH,
- WFNEWDESK, WFHSLSIZE, WFVSLSIZE, WFSCREEN, WFATTRIB,
- WFSIZTOP, GrafGrowbox, GrafShrinkbox, FormAlert,
- WindOpen, WindClose, WindDelete, WindCreate;
- FROM mtTerminal IMPORT TERMINAL, CloseTerminal, ChangeTerminal, GetTerminal,
- SetTerminal, GetMaximum, RedrawTerminal, ClipRect,
- CurrWidth, CurrHeight;
- FROM MagicStrings IMPORT Assign;
- FROM mtUtils IMPORT tRect, Min, Max;
- IMPORT MagicAES, mtAppl;
-
-
- CONST cMaxWin = 256; (* Maximal 0..256 Fenster *)
-
- CONST cOpen = 0; (* Fensterzustandflags *)
- cTerminal = 1;
- cGraphic = 2;
- cFulled = 3;
-
- CONST FrameRect = 0;
- WorkRect = 1;
-
-
- TYPE WINDOW = POINTER TO Window;
- Window = RECORD
- handle: sINTEGER; (* AES-Handle *)
- area: tRect; (* Arbeitsbereich des Windows *)
- vslSize: sCARDINAL; (* Gre Vertical Slider *)
- vslPos: sCARDINAL; (* Pos Vertical Slider *)
- hslSize: sCARDINAL; (* Gre Horizontal Slider *)
- hslPos: sCARDINAL; (* Pos Horizontal Slider *)
- elements: sBITSET; (* Fensterelemente *)
- zustand: sBITSET; (* Zustand-Flags *)
- name: ARRAY [0..255] OF CHAR;
- info: ARRAY [0..255] OF CHAR;
- term: TERMINAL;
- (* graph: GRAPHIC; *)
- next: WINDOW;
- END;
-
-
- VAR windows: WINDOW;
- graphics: BOOLEAN;
- in2: POINTER TO ADDRESS;
- r1, r2, r3: tRect;
- r: POINTER TO tRect;
- wx, wy, ww, wh: sINTEGER;
- ws, wz: sINTEGER;
- minSize: sINTEGER;
- i: sINTEGER;
- tr: RECORD
- adr: ADDRESS;
- d1, d2: sINTEGER;
- END;
-
- PROCEDURE Calc (what: sINTEGER; comp: sBITSET; in: tRect; VAR out: tRect);
- BEGIN
- AESIntIn[ 0]:= what;
- AESIntIn[ 1]:= CastToInt (comp);
- AESIntIn[ 2]:= in.x;
- AESIntIn[ 3]:= in.y;
- AESIntIn[ 4]:= in.w;
- AESIntIn[ 5]:= in.h;
- i:= AESCall(108, 6, 5, 0, 0);
- out.x:= AESIntOut[1];
- out.y:= AESIntOut[2];
- out.w:= AESIntOut[3];
- out.h:= AESIntOut[4];
- END Calc;
-
- PROCEDURE GetWindow (win: sINTEGER; VAR v: WINDOW): WINDOW;
- VAR p: WINDOW;
- c: CARDINAL;
- BEGIN
- p:= windows; v:= NIL;
- WHILE p # NIL DO
- IF p^.handle = win THEN RETURN p; END;
- v:= p; p:= p^.next;
- END;
- RETURN NIL;
- END GetWindow;
-
- PROCEDURE NewWindow (elements: sBITSET; REF name, info: ARRAY OF CHAR;
- VAR win: sINTEGER): BOOLEAN;
- VAR p, x1, x2: WINDOW;
- c: CARDINAL;
- BEGIN
- ALLOCATE (p, TSIZE(Window));
- IF p = NIL THEN RETURN FALSE; END;
- (* Erstmal ein Handle anfordern *)
- WindGet (0, WFFULLXYWH, r3);
- p^.handle:= WindCreate (elements, r3);
- IF p^.handle < 0 THEN DISPOSE (p); RETURN FALSE; END;
- (* Anfangswerte eintragen *)
- Calc (WorkRect, elements, r3, p^.area);
- IF VSLIDE IN elements THEN p^.vslSize:= 1000; p^.vslPos:= 1; END;
- IF HSLIDE IN elements THEN p^.hslSize:= 1000; p^.hslPos:= 1; END;
- Assign (name, p^.name);
- Assign (info, p^.info);
- p^.elements:= elements;
- p^.zustand:= {};
- p^.term:= TERMINAL (NIL);
- p^.next:= NIL;
- (* In die Liste eintragen *)
- IF windows = NIL THEN
- windows:= p;
- ELSE
- x1:= windows; x2:= windows;
- WHILE x1 # NIL DO x2:= x1; x1:= x1^.next; END;
- x2^.next:= p;
- END;
- win:= p^.handle;
- RETURN TRUE;
- END NewWindow;
-
- PROCEDURE DeleteWindow (VAR win: sINTEGER);
- VAR p, v: WINDOW;
- c: CARDINAL;
- BEGIN
- p:= GetWindow (win, v);
- IF p # NIL THEN
- IF cOpen IN p^.zustand THEN CloseWindow (p^.handle); END;
- IF v # NIL THEN v^.next:= p^.next; ELSE windows:= p^.next; END;
- DEALLOCATE (p, 0);
- END;
- AESIntIn[0]:= win; i:= AESCall(103, 1, 1, 0, 0);
- END DeleteWindow;
-
- PROCEDURE MaxWorkarea (win: sINTEGER; VAR rect: ARRAY OF LOC);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v); r:= ADR (rect);
- WindGet (0, WFFULLXYWH, r3);
- IF p # NIL THEN Calc (WorkRect, p^.elements, r3, r^);
- ELSE Calc (WorkRect, {0..12}, r3, r^);
- END;
- END MaxWorkarea;
-
- PROCEDURE CalcWorkarea (win: sINTEGER; VAR rect: ARRAY OF LOC);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v); r:= ADR (rect);
- IF p # NIL THEN r^:= p^.area;
- ELSE WindGet (win, WFCURRXYWH, r3);
- END;
- END CalcWorkarea;
-
- PROCEDURE OpenWindow (win: sINTEGER; rect: ARRAY OF LOC);
- VAR p, v: WINDOW;
- f: INTEGER;
- fr, wr: tRect;
- r: POINTER TO tRect;
- BEGIN
- p:= GetWindow (win, v); r:= ADR (rect);
- IF p # NIL THEN
- WITH p^ DO
- IF cOpen IN zustand THEN RETURN END;
- Calc (FrameRect, elements, r^, fr);
- Calc (WorkRect, elements, fr, area);
- IF graphics THEN
- WindGet (0, WFFULLXYWH, r3);
- r3.x:= r3.w DIV 2; r3.y:= r3.h DIV 2; r3.w:= 0; r3.h:= 0;
- r2:= area;
- GrafGrowbox (r3, r2);
- END;
- IF VSLIDE IN elements THEN
- r1.x:= vslPos; r1.y:= 0; r1.w:= 0; r1.h:= 0; WindSet (handle, 9, r1);
- r1.x:= vslSize; r1.y:= 0; r1.w:= 0; r1.h:= 0; WindSet (handle, 16, r1);
- END;
- IF HSLIDE IN elements THEN
- r1.x:= hslPos; r1.y:= 0; r1.w:= 0; r1.h:= 0; WindSet (handle, 8, r1);
- r1.x:= hslSize; r1.y:= 0; r1.w:= 0; r1.h:= 0; WindSet (handle, 15, r1);
- END;
- IF NAME IN elements THEN
- tr.adr:= ADR (name); tr.d1:= 0; tr.d2:= 0; WindSet (handle, 2, tr);
- END;
- IF INFO IN elements THEN
- tr.adr:= ADR (info); tr.d1:= 0; tr.d2:= 0; WindSet (handle, 3, tr);
- END;
- INCL (zustand, cOpen);
- END; (* WITH *)
- WindOpen (win, fr);
- END;
- END OpenWindow;
-
- PROCEDURE CloseWindow (win: sINTEGER);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p # NIL THEN
- WITH p^ DO
- IF graphics THEN
- r2.x:= area.w DIV 2; r2.y:= area.h DIV 2; r2.w:= 0; r2.h:= 0;
- GrafShrinkbox (r2, area);
- END;
- EXCL (zustand, cOpen);
- END;
- END;
- AESIntIn[0]:= win; i:= AESCall(102, 1, 1, 0, 0);
- END CloseWindow;
-
- PROCEDURE CloseWindows;
- VAR p: WINDOW;
- BEGIN
- p:= windows;
- WHILE p # NIL DO CloseWindow (p^.handle); p:= p^.next; END;
- END CloseWindows;
-
- PROCEDURE DeleteWindows;
- VAR p: WINDOW;
- BEGIN
- p:= windows;
- WHILE p # NIL DO DeleteWindow (p^.handle); p:= p^.next; END;
- END DeleteWindows;
-
- PROCEDURE OwnWindow (win: sINTEGER): BOOLEAN;
- VAR p: WINDOW;
- BEGIN
- p:= windows;
- WHILE p # NIL DO
- IF p^.handle = win THEN RETURN TRUE; END; p:= p^.next;
- END;
- RETURN FALSE;
- END OwnWindow;
-
- PROCEDURE WindowTop (win: sINTEGER);
- VAR p, v: WINDOW;
- ot: TERMINAL;
- i: sINTEGER;
- BEGIN
- p:= GetWindow (win, v);
- IF p # NIL THEN
- IF NOT (cOpen IN p^.zustand) THEN RETURN END;
- AESIntIn[0]:= p^.handle; AESIntIn[1]:= 10; i:= AESCall(105, 6, 1, 0, 0);
- IF cTerminal IN p^.zustand THEN ot:= ChangeTerminal (p^.term); END;
- END;
- END WindowTop;
-
- PROCEDURE TopWindow (): sINTEGER;
- BEGIN
- AESIntIn[0]:= 0; AESIntIn[1]:= 10; i:= AESCall(104, 2, 5, 0, 0);
- RETURN AESIntOut[1];
- END TopWindow;
-
- PROCEDURE WindowFulled (win: sINTEGER);
- VAR p, v: WINDOW;
- r: tRect;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- WindGet (win, WFFULLXYWH, r);
- WindSet (win, WFCURRXYWH, r);
- ELSE
- IF NOT (cOpen IN p^.zustand) THEN RETURN END;
- IF cFulled IN p^.zustand THEN
- WindGet (p^.handle, WFPREVXYWH, r); EXCL (p^.zustand, cFulled);
- ELSE
- WindGet (p^.handle, WFFULLXYWH, r); INCL (p^.zustand, cFulled);
- END;
- WITH p^ DO
- WindSet (handle, WFCURRXYWH, r);
- Calc (WorkRect, elements, r, area);
- IF cTerminal IN zustand THEN SetTerminal (area); END;
- END;
- END;
- END WindowFulled;
-
- PROCEDURE UpdateTerm (a: tRect);
- VAR r, c: tRect;
- BEGIN
- WindGet (0, WFFULLXYWH, c);
- SetTerminal (a);
- r.x:= a.x; r.y:= a.y; r.w:= c.w; r.h:= c.h;
- IF ((a.x + a.w) > c.w) OR ((a.y + a.h) > c.h) THEN
- ClipRect (TRUE, r);
- ELSE
- ClipRect (FALSE, r);
- END;
- END UpdateTerm;
-
- PROCEDURE WindowPos (win: sINTEGER; xx, yy: sINTEGER);
- VAR p, v: WINDOW;
- r, c: tRect;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- WindGet (win, WFCURRXYWH, r); r.x:= xx; r.y:= yy;
- WindSet (win, WFCURRXYWH, r);
- RETURN
- ELSE
- IF NOT (cOpen IN p^.zustand) THEN RETURN END;
- WITH p^ DO
- Calc (FrameRect, elements, area, r); r.x:= xx; r.y:= yy;
- WindSet (handle, WFCURRXYWH, r);
- Calc (WorkRect, elements, r, area);
- EXCL (p^.zustand, cFulled);
- IF cTerminal IN zustand THEN UpdateTerm (area); END;
- END; (* WITH *)
- END;
- END WindowPos;
-
- PROCEDURE WindowSize (win: sINTEGER; ww, hh: sINTEGER);
- VAR p, v: WINDOW;
- r, c: tRect;
- i, h: sINTEGER;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- WindGet (win, WFCURRXYWH, r); r.w:= ww; r.h:= hh;
- WindSet (win, WFCURRXYWH, r);
- ELSE
- IF NOT (cOpen IN p^.zustand) THEN RETURN END;
- WITH p^ DO
- Calc (FrameRect, elements, area, r);
- IF ww < minSize THEN ww:= minSize; END; r.w:= ww;
- IF hh < minSize THEN hh:= minSize; END; r.h:= hh;
- Calc (WorkRect, elements, r, area);
- IF cTerminal IN zustand THEN
- area.w:= (area.w DIV CurrWidth) * CurrWidth;
- area.h:= (area.h DIV CurrHeight) * CurrHeight;
- Calc (FrameRect, elements, area, r);
- END;
- WindSet (handle, WFCURRXYWH, r);
- Calc (WorkRect, elements, r, area);
- EXCL (p^.zustand, cFulled);
- IF cTerminal IN zustand THEN UpdateTerm (area); END;
- END;
- END;
- END WindowSize;
-
- (*$W-*)
- PROCEDURE WindowName (win: sINTEGER; REF name: ARRAY OF CHAR);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- tr.adr:= ADR (name); tr.d1:= 0; tr.d2:= 0; WindSet (win, 2, tr);
- ELSE
- IF NAME IN p^.elements THEN
- Assign (name, p^.name);
- IF cOpen IN p^.zustand THEN
- tr.adr:= ADR (p^.name); tr.d1:= 0; tr.d2:= 0;
- WindSet (p^.handle, 2, tr);
- END;
- END;
- END;
- END WindowName;
-
- PROCEDURE WindowInfo (win: sINTEGER; REF info: ARRAY OF CHAR);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- tr.adr:= ADR (info); tr.d1:= 0; tr.d2:= 0; WindSet (win, 2, tr);
- ELSE
- IF INFO IN p^.elements THEN
- Assign (info, p^.info);
- IF (cOpen IN p^.zustand) THEN
- tr.adr:= ADR (p^.info); tr.d1:= 0; tr.d2:= 0;
- WindSet (p^.handle, 3, tr);
- END;
- END;
- END;
- END WindowInfo;
- (*$W=*)
-
- PROCEDURE WindowSlider (win, which, max, act, fpos: sINTEGER);
- VAR p, v: WINDOW;
- c, d: sCARDINAL;
- x, y: sINTEGER;
- sv, pv: BOOLEAN;
- BEGIN
- sv:= TRUE; pv:= TRUE;
-
- (* Gre berechnen *)
- IF max = 0 THEN
- c:= 1000;
- ELSE
- c:= Min (1000, SHORT ((LONG (1000) * LONG (act)) DIV LONG (max) + LONG (1)));
- END;
-
- (* Position berechnen *)
- IF (fpos = 0) OR (max < act) THEN
- d:= 0;
- ELSE
- d:= SHORT ((LONG (1000) * LONG(fpos) + LONG (1)) DIV LONG (max - act));
- END;
-
- p:= GetWindow (win, v);
- IF p # NIL THEN
- IF which = VSlider THEN
- IF p^.vslPos = d THEN pv:= FALSE; ELSE p^.vslPos:= d; END;
- IF p^.vslSize = c THEN sv:= FALSE; ELSE p^.vslSize:= c; END;
- ELSE
- IF p^.hslPos = d THEN pv:= FALSE; ELSE p^.hslPos:= d; END;
- IF p^.hslSize = c THEN sv:= FALSE; ELSE p^.hslSize:= c; END;
- END;
- END;
-
- IF which = VSlider THEN x:= 9; y:= 16; ELSE x:= 8; y:= 15; END;
-
- IF pv THEN (* Position *)
- AESIntIn[0]:= win; AESIntIn[1]:= x; AESIntIn[2]:= d;
- i:= AESCall(105, 6, 1, 0, 0);
- END;
-
- IF sv THEN (* Gre *)
- AESIntIn[0]:= win; AESIntIn[1]:= y; AESIntIn[2]:= c;
- i:= AESCall(105, 6, 1, 0, 0);
- END;
-
- END WindowSlider;
-
-
- PROCEDURE GetElements (win: sINTEGER; VAR elements: sBITSET;
- VAR vsize, vpos, hsize, hpos: sINTEGER;
- VAR name, info: ARRAY OF CHAR);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN
- elements:= {}; vsize:= -1; vpos:= -1; hsize:= -1; hpos:= -1;
- Assign ('', name); Assign ('', info);
- ELSE
- elements:= p^.elements;
- vsize:= p^.vslSize;
- vpos:= p^.vslPos;
- hsize:= p^.hslSize;
- hpos:= p^.hslPos;
- Assign (p^.name, name);
- Assign (p^.info, info);
- END;
- END GetElements;
-
- PROCEDURE ConnectTerminal (win: sINTEGER; term: TERMINAL);
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p = NIL THEN RETURN END;
- INCL (p^.zustand, cTerminal); p^.term:= term;
- END ConnectTerminal;
-
- PROCEDURE WindowTerminal (win: sINTEGER): TERMINAL;
- VAR p, v: WINDOW;
- BEGIN
- p:= GetWindow (win, v);
- IF p # NIL THEN
- IF cTerminal IN p^.zustand THEN RETURN p^.term; END;
- END;
- RETURN TERMINAL (NIL);
- END WindowTerminal;
-
- PROCEDURE RectList (win: sINTEGER; flag: sINTEGER;
- VAR rect: ARRAY OF LOC): BOOLEAN;
- VAR r: POINTER TO tRect;
- p, v: WINDOW;
- b: BOOLEAN;
- BEGIN
- b:= FALSE; r:= ADR (rect);
- WindGet (win, flag + 11, r^);
- b:= NOT ((r^.w = 0) OR (r^.h = 0));
- RETURN b;
- END RectList;
-
- PROCEDURE RcIntersect (VAR rc1, rc2: ARRAY OF LOC): BOOLEAN;
- VAR r: tRect;
- p1, p2: POINTER TO tRect;
- b: BOOLEAN;
- BEGIN
- p1:= ADR(rc1); p2:= ADR(rc2);
- r.x:= Max (p2^.x, p1^.x);
- r.y:= Max (p2^.y, p1^.y);
- r.w:= Min (p2^.x + p2^.w, p1^.x + p1^.w);
- r.h:= Min (p2^.y + p2^.h, p1^.y + p1^.h);
- r.w:= r.w - r.x;
- r.h:= r.h - r.y;
- p2^:= r;
- RETURN ((p2^.w > 0) AND (p2^.h > 0));
- END RcIntersect;
-
- PROCEDURE UseGraphics (use: BOOLEAN);
- BEGIN
- graphics:= use;
- END UseGraphics;
-
- VAR c: sCARDINAL;
-
- BEGIN
- mtAppl.InstallTermproc (DeleteWindows);
- windows:= NIL;
- minSize:= 5 * mtAppl.BoxHeight;
- graphics:= TRUE;
- in2:= ADR(AESIntIn[2]);
- END mtWindows.
-
-